﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VOL.Core.Extensions;
using VOL.Entity.DomainModels;
using VOL.SmartHealthcare.Infrastructure;
using VOL.Team.TeamIServices.ProductManagement.IServices;

namespace VOL.Team.TeamIServices.ProductManagement.Services
{
    /// <summary>
    /// 生产管理-工单台账-xzc
    /// </summary>
    public class TicketLedgerServices: ITicketLedgerServices
    {
        private readonly IBaseRepository<TicketLedger> _ticketledgerRepositroy;
        private readonly IBaseRepository<BOM> _bomRepository;
        private readonly IBaseRepository<Operational> _operationalRepository;

        public TicketLedgerServices(IBaseRepository<TicketLedger> ticketledgerRepositroy, IBaseRepository<BOM> bomRepository, IBaseRepository<Operational> operationalRepository)
        {
            _ticketledgerRepositroy = ticketledgerRepositroy;
            _bomRepository = bomRepository;
            _operationalRepository = operationalRepository;
        }
        /// <summary>
        /// 生产管理-工单甘特图-新增工单台账-xzc
        /// </summary>
        /// <param name="ticketledger"></param>
        /// <returns></returns>
        public async Task<int> AddTicketLedger(TicketLedger ticketledger)
        {
            try
            {
                var tickrtledgerList = await _ticketledgerRepositroy.AddAsync(ticketledger);
                return tickrtledgerList;
            }
            catch (Exception)
            {
                throw;
            }
        }
        /// <summary>
        /// 生产管理-工单甘特图-修改工单台账-xzc
        /// </summary>
        /// <param name="ticketledger"></param>
        /// <returns></returns>
        public async Task<int> UpdateTicketLedger(TicketLedger ticketledger)
        {
            try
            {
                var tickrtledgerList = await _ticketledgerRepositroy.UpdateAsync(ticketledger);
                return tickrtledgerList;
            }
            catch (Exception)
            {
                throw;
            }
        }
        /// <summary>
        /// 生产管理-工单甘特图-查询工单台账-xzc
        /// </summary>
        /// <param name="ticketledger"></param>
        /// <returns></returns>
        public IQueryable<TicketLedger> GetTicketLedgerList(string? tickeNumber,int? ordersState)
        {
            try
            {
                var tickrtledgerList = _ticketledgerRepositroy.GetAll();
                tickrtledgerList = tickrtledgerList.WhereIF(tickeNumber != null, m => m.TickeNumber == tickeNumber);
                tickrtledgerList = tickrtledgerList.WhereIF(ordersState != null, m => m.OrdersState == ordersState);
                return tickrtledgerList;
            }
            catch (Exception)
            {
                throw;
            }
        }
        /// <summary>
        /// 生产管理-新增甘特图-BOM查询-xzc
        /// </summary>
        /// <param name="boms"></param>
        /// <returns></returns>
        public IQueryable<BOM> GetBOM()
        {
            try
            {
                var bomList = _bomRepository.GetAll();
                return bomList;
            }
            catch (Exception)
            {
                throw;
            }
        }
        /// <summary>
        /// 生产管理-新增甘特图-工艺路线查询-xzc
        /// </summary>
        /// <param name="boms"></param>
        /// <returns></returns>
        public IQueryable<Operational> GetOperational()
        {
            try
            {
                var operationalList = _operationalRepository.GetAll();
                return operationalList;
            }
            catch (Exception)
            {
                throw;
            }
        }
    }
}
